package com.ruoyi.web.controller.system;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ReportElement;
import com.ruoyi.system.service.IReportElementService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 模版组件Controller
 * 
 * @author ruoyi
 * @date 2021-06-16
 */
@RestController
@RequestMapping("/system/element")
public class ReportElementController extends BaseController
{
    @Autowired
    private IReportElementService reportElementService;

    /**
     * 查询模版组件列表
     */
//    @PreAuthorize("@ss.hasPermi('system:element:list')")
    @GetMapping("/list")
    public TableDataInfo list(ReportElement reportElement)
    {
        startPage();
        List<ReportElement> list = reportElementService.selectReportElementList(reportElement);
        return getDataTable(list);
    }

    /**
     * 导出模版组件列表
     */
    @PreAuthorize("@ss.hasPermi('system:element:export')")
    @Log(title = "模版组件", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReportElement reportElement)
    {
        List<ReportElement> list = reportElementService.selectReportElementList(reportElement);
        ExcelUtil<ReportElement> util = new ExcelUtil<ReportElement>(ReportElement.class);
        return util.exportExcel(list, "模版组件数据");
    }

    /**
     * 获取模版组件详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:element:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(reportElementService.selectReportElementById(id));
    }

    /**
     * 新增模版组件
     */
    @PreAuthorize("@ss.hasPermi('system:element:add')")
    @Log(title = "模版组件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReportElement reportElement)
    {
        return toAjax(reportElementService.insertReportElement(reportElement));
    }

    /**
     * 修改模版组件
     */
    @PreAuthorize("@ss.hasPermi('system:element:edit')")
    @Log(title = "模版组件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReportElement reportElement)
    {
        return toAjax(reportElementService.updateReportElement(reportElement));
    }

    /**
     * 删除模版组件
     */
    @PreAuthorize("@ss.hasPermi('system:element:remove')")
    @Log(title = "模版组件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(reportElementService.deleteReportElementByIds(ids));
    }
}
